<?php

namespace addons\shopro\service\pay;

use app\admin\model\Children;
use app\admin\model\market\Acceleration;
use app\admin\model\shopro\Goods;
use app\admin\model\shopro\goods\SkuPrice;
use app\admin\model\shopro\order\OrderItem;
use app\admin\model\shopro\user\WalletLog;
use app\common\model\ScoreLog;
use app\common\model\UserStaticLogModel;
use think\Db;
use think\Log;
use app\admin\model\shopro\Pay as PayModel;
use app\admin\model\shopro\user\User;
use app\admin\model\shopro\order\Action;
use think\helper\Str;
use addons\shopro\service\Wallet as WalletService;


class PayOper
{
    protected $user = null;

    /**
     * 实例化
     *
     * @param mixed $user
     */
    public function __construct($user = null)
    {
        // 优先使用传入的用户
        $this->user = $user ? (is_numeric($user) ? User::get($user) : $user) : auth_user();
    }



    /**
     * 微信预付款
     *
     * @param think\Model $order
     * @param float $money
     * @param string $order_type
     * @return think\Model
     */
    public function wechat($order, $money, $order_type = 'order')
    {
        $pay = $this->addPay($order, [
            'order_type' => $order_type,
            'pay_type' => 'wechat',
            'pay_fee' => $money,
            'real_fee' => $money,
            'transaction_id' => null,
            'payment_json' => [],
            'status' => PayModel::PAY_STATUS_UNPAID
        ]);

        return $pay;
    }


    /**
     * 支付宝预付款
     *
     * @param think\Model $order
     * @param float $money
     * @param string $order_type
     * @return think\Model
     */
    public function alipay($order, $money, $order_type = 'order')
    {
        $pay = $this->addPay($order, [
            'order_type' => $order_type,
            'pay_type' => 'alipay',
            'pay_fee' => $money,
            'real_fee' => $money,
            'transaction_id' => null,
            'payment_json' => [],
            'status' => PayModel::PAY_STATUS_UNPAID
        ]);

        return $pay;
    }



    /**
     * 代金券付款
     *
     * @param think\Model $order
     * @param float $money
     * @param string $order_type
     * @return think\Model
     */
    public function money($order, $money, $order_type = 'order')
    {
        // 代金券支付金额，传入金额和剩余支付金额最大值
        $money = $order->remain_pay_fee > $money ? $money : $order->remain_pay_fee;     // 混合支付不能超过订单应支付总金额

        // 扣除用户代金券
        WalletService::change($this->user, 'money', -$money, 'order_pay', [
            'order_id' => $order->id,
            'order_sn' => $order->order_sn,
            'order_type' => $order_type,
        ]);
        //'gold', 'golden', 'silver'
        if($order->goods_golden > 0){

            WalletService::change($this->user, 'golden', -$order->goods_golden, 'order_pay', [
                'order_id' => $order->id,
                'order_sn' => $order->order_sn,
                'order_type' => $order_type,
            ],'购买商品抵扣');
        }
        if($order->goods_silver > 0){
            WalletService::change($this->user, 'silver', -$order->goods_silver, 'order_pay', [
                'order_id' => $order->id,
                'order_sn' => $order->order_sn,
                'order_type' => $order_type,
            ],'购买商品抵扣');
        }
        if($order->goods_gold > 0){
            WalletService::change($this->user, 'gold', -$order->goods_gold, 'order_pay', [
                'order_id' => $order->id,
                'order_sn' => $order->order_sn,
                'order_type' => $order_type,
            ],'购买商品抵扣');
        }
        // 添加支付记录
        $pay = $this->addPay($order, [
            'order_type' => $order_type,
            'pay_type' => 'money',
            'pay_fee' => $money,
            'real_fee' => $money,
            'transaction_id' => null,
            'payment_json' => [],
            'status' => PayModel::PAY_STATUS_PAID
        ]);

        // 代金券直接支付成功，更新订单剩余应付款金额，并检测订单状态
        $this->fenyong($order,$this->user);
        return $this->checkAndPaid($order, $order_type);
    }



    /**
     * @menu 分积分
     * @
     * @Date:2024-04-15 15:22
     */
    public function fenyong($order, $user)
    {
        $goodsModel    = new \app\admin\model\shopro\goods\Goods();
        $gift_score    = 0;
        $principal = 0;
        foreach ($order['items'] as $k => $v) {
            $goodsInfo = $goodsModel->where(['id' => $v->goods_id, 'type' => 'normal'])->find();
            if ($goodsInfo) {
                if($goodsInfo->firepower_type == 'firepower_scale' && $goodsInfo->firepower_num > 0){
                    $gift_score += bcmul($v->pay_fee, ($goodsInfo->firepower_num / 100), 2);
                    $score_release_bili =  (100-$goodsInfo->firepower_num)/100;
                    $principal += bcmul($v->pay_fee, $score_release_bili, 2);
                }

            }
        }
        $params['id']  = $order['user_id'];
        $params['ext'] = ['order_id' => $order['id']];
        if ($gift_score) {
            $params['type']   = 'score';
            $params['amount'] = $gift_score;
            $params['memo']   = '自购奖励';
            Db::transaction(function () use ($params) {
                return WalletService::change($params['id'], $params['type'], $params['amount'], 'order', $params['ext'],
                    $params['memo']);
            });
        }
        if($principal){
            $params['type']   = 'principal';
            $params['amount'] = $principal;
            $params['memo']   = '自购奖励';
            Db::transaction(function () use ($params) {
                return WalletService::change($params['id'], $params['type'], $params['amount'], 'order', $params['ext'],
                    $params['memo']);
            });
        }
        if($user['parent_user_id'] > 0){
            $parent_user_info = \app\common\model\User::where(['id'=>$user['parent_user_id']])->field('id')->find();
            if($parent_user_info){
                $params['id']  = $user['parent_user_id'];
                $parent_score  = bcmul($order['pay_fee'], config('site.parent_user_bili'),2)/100;
                if ($parent_score > 0) {
                    $params['type']   = 'score';
                    $params['amount'] = $parent_score;
                    $params['memo']   = '推荐奖';
                    Db::transaction(function () use ($params) {
                        return WalletService::change($params['id'], $params['type'], $params['amount'], 'order', $params['ext'],
                            $params['memo']);
                    });
                }
            }
        }
        if($user['is_qrcode'] == 0){
            db('user')->where(['id'=>$user['id']])->update(['is_qrcode'=>1,'qrcode_time'=>time()]);
        }
//        jicha($user, $order['order_amount'], $user->level);
    }


    public function qiyongfenyong($order, $user)
    {
        $skuPriceModel = new SkuPrice();
        $goodsModel    = new \app\admin\model\shopro\goods\Goods();
        $gift_score    = 0;
        $gift_silver   = 0;
        $principal_score = 0;
//        $gift_firepower        = 0;
//        $gift_firepower_parent = 0;
        $parent_user_info  = '';
        $parent_user_money = 0;
        if ($user->parent_user_id) {
            $parent_user_info = \app\common\model\User::where(['id' => $user->parent_user_id])->field('id,score,principal,level,is_marketplace,parent_user_id')->find();
        }
        $two_user_money = 0;
        $two_user_info  = '';
        if (!empty($parent_user_info->parent_user_id)) {
            $two_user_info = \app\common\model\User::where(['id' => $parent_user_info->parent_user_id])->field('id,score,principal,level,is_marketplace')->find();
        }
        $user_ids = \app\common\model\User::where(['parent_user_id'=>$user->id])->column('id');
        $is_shichang = \app\admin\model\shopro\order\Order::where(['status'=>'paid'])->whereIn('user_id', $user_ids)->count();
        $parent_score = 0;
        foreach ($order['items'] as $k => $v) {
            $goodsInfo = $goodsModel->where(['id' => $v->goods_id, 'type' => 'normal'])->find();
            if ($goodsInfo) {
                if($goodsInfo->marketplace_times > 0){
                    if($is_shichang){
                        $gift_score = bcmul($order['order_amount'], $goodsInfo->marketplace_times);
                    }
                    $principal_score = $order['order_amount'];
                    UserStaticLogModel::create(['user_id'=>$user->id,'order_id'=>$order['id'],'goods_id'=>$v->goods_id,'money'=>$principal_score,'rebate_time'=>strtotime(date('Y-m-d',30*86400+time()))]);
                }
                if($goodsInfo->type == 'normal'){
                    if ($parent_user_info) {
                        if($parent_user_info->principal || $parent_user_info->score){
                            $parent_user_money = bcmul($order['order_amount'], ($goodsInfo->one_scale / 100), 2);
                        }
                        if($parent_user_info->is_marketplace == 0){
                            $goods_id = OrderItem::where(['user_id'=>$parent_user_info->id])->value('goods_id');
                            if($goods_id){
                                $parent_user_goods = Goods::where(['id' => $goods_id, 'type' => 'normal'])->find();
                                if(!empty($parent_user_goods->marketplace_times)){
                                    $parent_score = bcmul($parent_user_info->principal,$parent_user_goods->marketplace_times);
                                    $parent_user_info->is_marketplace = 1;
                                    $parent_user_info->save();

                                }
                            }
                        }
                    }
                    if ($two_user_info) {
                        if($two_user_info->principal || $two_user_info->score){
                            $two_user_money    = bcmul($order['order_amount'], ($goodsInfo->two_scale / 100), 2);
                        }
                    }
                }
                //赠送银豆
                if ($goodsInfo->silver_type == 'silver_scale_type') {
                    $gift_silver += bcmul($v->pay_fee, ($goodsInfo->silver_type_num / 100), 2);
                } elseif ($goodsInfo->firepower_type == 'silver_immobilization') {
                    $gift_silver = $goodsInfo->silver_type_num;
                }
            }
        }
        //倍数积分
        $params['id']  = $order['user_id'];
        $params['ext'] = ['order_id' => $order['id']];
        if ($gift_score) {
            $params['type']   = 'score';
            $params['amount'] = $gift_score;
            $params['memo']   = '自购奖励';
            Db::transaction(function () use ($params) {
                return WalletService::change($params['id'], $params['type'], $params['amount'], 'release', $params['ext'],
                    $params['memo']);
            });
        }
        if($parent_score){
            Db::transaction(function () use ($parent_user_info,$parent_score,$order) {
                return WalletService::change($parent_user_info->id, 'score', $parent_score, 'release', ['order_id'=>$order['user_id']],
                    '动态积分');
            });
        }
        //本金
        if ($principal_score) {
            $params['type']   = 'principal';
            $params['amount'] = $principal_score;
            $params['memo']   = '自购奖励';
            Db::transaction(function () use ($params) {
                return WalletService::change($params['id'], $params['type'], $params['amount'], 'order', $params['ext'],
                    $params['memo']);
            });
        }
        //赠送银豆
        if ($gift_silver) {
            $params['type']   = 'silver';
            $params['amount'] = $gift_silver;
            $params['memo']   = '自购奖励';
            Db::transaction(function () use ($params) {
                return WalletService::change($params['id'], $params['type'], $params['amount'], 'order', $params['ext'],
                    $params['memo']);
            });
        }
        //帕点分红
        $childrenData = Children::where(['children_id' => $order['user_id']])->order('level asc')->column('member_id');
        if ($childrenData) {
            $userModel = new \app\common\model\User();
            $userArray = [];
            $ke        = -1;
            foreach ($childrenData as $kk => $vv) {
                $pa_rate = $userModel->where(['id' => $vv, 'pa_rate' => ['gt', 0]])->value('pa_rate');
                if ($pa_rate) {
                    $ke++;
                    $userArray[$ke]['user_id'] = $vv;
                    $userArray[$ke]['pa_rate'] = $pa_rate;
                }
            }
            if (!empty($userArray[0]['pa_rate'])) {
                $is_two = true;
                if ($userArray[0]['pa_rate'] >= 15 || empty($userArray[1]['pa_rate'])) {
                    $is_two = false;
                }
                $order_amount             = $order->order_amount;
                $gold                     = bcmul($order_amount, ($userArray[0]['pa_rate'] / 100), 2);
                $params['type']           = 'gold';
                $params['amount']         = $gold;
                $params['memo']           = 'PA点收益';
                $params['id']             = $userArray[0]['user_id'];
                $params['ext']['user_id'] = $userArray[0]['user_id'];
                Db::transaction(function () use ($params) {
                    return WalletService::change($params['id'], $params['type'], $params['amount'], 'order',
                        $params['ext'],
                        $params['memo']);
                });
                if ($is_two) {
                    $pa_rate                  = $userArray[1]['pa_rate'] - $userArray[0]['pa_rate'];
                    $gold                     = bcmul($order_amount, ($pa_rate / 100), 2);
                    $params['type']           = 'gold';
                    $params['amount']         = $gold;
                    $params['memo']           = 'PA点收益';
                    $params['id']             = $userArray[1]['user_id'];
                    $params['ext']['user_id'] = $userArray[0]['user_id'];;
                    Db::transaction(function () use ($params) {
                        return WalletService::change($params['id'], $params['type'], $params['amount'], 'order',
                            $params['ext'],
                            $params['memo']);
                    });
                }
            }

        }
        if($parent_user_money){
            if($parent_user_info->principal >= $parent_user_money){
                $this->RecommendedFenyong($parent_user_info,$parent_user_money,'推荐收益','principal');
            }else{
                if($parent_user_info->principal == 0){
                    if($parent_user_info->score > 0){
                        if($parent_user_info->score >= $parent_user_money){
                            $this->RecommendedFenyong($parent_user_info,$parent_user_money,'推荐收益','score');
                        }else{
                            $this->RecommendedFenyong($parent_user_info,$parent_user_info->score,'推荐收益','score');
                        }
                    }
                }else{
                    $parent_user_money -= $parent_user_info->principal;
                    $this->RecommendedFenyong($parent_user_info,$parent_user_info->principal,'推荐收益','principal');
                    if($parent_user_info->score >= $parent_user_money){
                        $this->RecommendedFenyong($parent_user_info,$parent_user_money,'推荐收益','score');
                    }else{
                        $this->RecommendedFenyong($parent_user_info,$parent_user_info->score,'推荐收益','score');
                    }
                }

            }
        }

        if($two_user_money){
            if($two_user_info->principal >= $two_user_money){
                $this->RecommendedFenyong($two_user_info,$two_user_money,'间推收益','principal');
            }else{
                if($two_user_info->principal == 0){
                    if($two_user_info->score > 0){
                        if($two_user_info->score >= $two_user_money){
                            $this->RecommendedFenyong($two_user_info,$two_user_money,'间推收益','score');
                        }else{
                            $this->RecommendedFenyong($two_user_info,$two_user_info->score,'间推收益','score');
                        }
                    }
                }else{
                    $two_user_money -= $two_user_info->principal;
                    $this->RecommendedFenyong($two_user_info,$two_user_info->principal,'间推收益','principal');
                    if($two_user_info->score >= $two_user_money){
                        $this->RecommendedFenyong($two_user_info,$two_user_money,'间推收益','score');
                    }else{
                        $this->RecommendedFenyong($two_user_info,$two_user_info->score,'间推收益','score');
                    }
                }
            }
        }
        jicha($user, $order['order_amount'], $user->level);
    }

    public function RecommendedFenyong($userInfo,$release,$memo,$type){
        $golen_scale       = config('site.golen_scale') / 100;        //黄金券比例
        $slive_scale       = (100 - config('site.golen_scale')) / 100;//银豆比例
        WalletService::change($userInfo->id, $type, -$release, 'release',
            ['level' => $userInfo->level],
            $memo);
        $golden      = bcmul($release, $golen_scale, 2);
        if($golden > 0){
            WalletService::change($userInfo->id, 'golden', $golden, 'release_golden',
                ['level' => $userInfo->level],
                $memo);
        }
        $slive       = bcmul($release, $slive_scale, 2);
        if($slive > 0){
            WalletService::change($userInfo->id, 'silver', $slive, 'release_slive ',
                ['level' => $userInfo->level],
                $memo);
        }
    }




    /**
     * 积分支付
     *
     * @param think\Model $order
     * @param float $money
     * @param string $order_type
     * @return think\Model
     */
    public function score($order, $score, $order_type = 'order')
    {
        if ($order_type == 'order') {
            if ($order['type'] == 'score') {
                $log_type = 'score_shop_pay';
                $real_fee = $score;         // 积分商城真实抵扣，就是积分
            } else {
                $log_type = 'order_pay';
                // $real_fee = ;         // 积分商城真实抵扣，就是积分
                error_stop('缺少积分抵扣金额');       // 支持积分抵扣时补全
            }
        }

        WalletService::change($this->user, 'score', -$score, $log_type, [
            'order_id' => $order->id,
            'order_sn' => $order->order_sn,
            'order_type' => $order_type,
        ]);

        // 添加支付记录
        $pay = $this->addPay($order, [
            'order_type' => $order_type,
            'pay_type' => 'score',
            'pay_fee' => $score,
            'real_fee' => $real_fee,
            'transaction_id' => null,
            'payment_json' => [],
            'status' => PayModel::PAY_STATUS_PAID
        ]);

        // 积分直接支付成功，更新订单剩余应付款金额，并检测订单状态
        return $this->checkAndPaid($order, $order_type);
    }


    /**
     * 线下支付(货到付款)
     *
     * @param think\Model $order
     * @param float $money
     * @param string $order_type
     * @return think\Model
     */
    public function offline($order, $money, $order_type = 'order')
    {
        // 添加支付记录
        $pay = $this->addPay($order, [
            'order_type' => $order_type,
            'pay_type' => 'offline',
            'pay_fee' => $money,
            'real_fee' => $money,
            'transaction_id' => null,
            'payment_json' => [],
            'status' => PayModel::PAY_STATUS_PAID
        ]);

        // 更新订单剩余应付款金额，并检测订单状态
        return $this->checkAndPaid($order, $order_type, 'offline');
    }


    /**
     * 微信支付宝支付回调通用方法
     *
     * @param \think\Model $pay
     * @param array $notify
     * @return void
     */
    public function notify($pay, $notify)
    {
        $pay->status = PayModel::PAY_STATUS_PAID;
        $pay->transaction_id = $notify['transaction_id'];
        $pay->buyer_info = $notify['buyer_info'];
        $pay->payment_json = $notify['payment_json'];
        $pay->paid_time = time();
        $pay->save();

        $orderModel = $this->getOrderModel($pay->order_type);
        $order = new $orderModel();
        $order = $order->where('id', $pay->order_id)->find();
        if (!$order) {
            // 订单未找到，非正常情况，这里记录日志
            Log::write('pay-notify-error:order notfound;pay:' . json_encode($pay) . ';notify:' . json_encode($notify));
            return false;
        }

        if ($order->status == $order::STATUS_UNPAID) {      // 未支付，检测支付状态
            $order = $this->checkAndPaid($order, $pay->order_type);
        }

        return $order;
    }



    /**
     * 更新订单剩余应支付金额，并且检测订单状态
     *
     * @param think\Model $order
     * @param string $order_type
     * @return think\Model
     */
    public function checkAndPaid($order, $order_type, $pay_mode = 'online')
    {
        // 获取订单已支付金额
        $payed_fee = $this->getPayedFee($order, $order_type);

        $remain_pay_fee = bcsub($order->pay_fee, (string)$payed_fee, 2);

        $order->remain_pay_fee = $remain_pay_fee;
        if ($remain_pay_fee <= 0) {
            $order->remain_pay_fee = 0;
            $order->paid_time = time();
            $order->status = $order::STATUS_PAID;
        } else {
            if ($pay_mode == 'offline') {
                // 订单未支付成功，并且是线下支付(货到付款)，将订单状态改为 pending
                $order->status = $order::STATUS_PENDING;
                $order->ext = array_merge($order->ext, ['pending_time' => time()]);     // 货到付款下单时间
                $order->pay_mode = 'offline';
            }
        }
        $order->save();

        if ($order->status == $order::STATUS_PAID) {
            // 订单支付完成
            $user = User::where('id', $order->user_id)->find();
            if ($order_type == 'order') {
                if ($pay_mode == 'offline') {
                    Action::add($order, null, auth_admin(), 'admin', '管理员操作自动货到付款支付成功');
                    // 在控制器执行后续内容，这里不再处理
                    return $order;
                } else {
                    Action::add($order, null, $user, 'user', '用户支付成功');
                    // 支付成功后续使用异步队列处理
                    \think\Queue::push('\addons\shopro\job\OrderPaid@paid', ['order' => $order, 'user' => $user], 'shopro-high');
                }
            } else if ($order_type == 'trade_order') {
                // 支付成功后续使用异步队列处理
                \think\Queue::push('\addons\shopro\job\trade\OrderPaid@paid', ['order' => $order, 'user' => $user], 'shopro-high');
            }
        } else if ($order->status == $order::STATUS_PENDING) {
            // 货到付款，添加货到付款队列（后续也需要处理拼团， 减库存等等）
            $user = User::where('id', $order->user_id)->find();
            if ($order_type == 'order') {
                Action::add($order, null, $user, 'user', '用户货到付款下单成功');

                // 支付成功后续使用异步队列处理
                \think\Queue::push('\addons\shopro\job\OrderPaid@offline', ['order' => $order, 'user' => $user], 'shopro-high');
            }
        }

        return $order;
    }



    /**
     * 获取订单已支付金额，商城订单 计算 积分抵扣金额
     *
     * @param \think\Model $order
     * @param string $order_type
     * @return string
     */
    public function getPayedFee($order, $order_type)
    {
        // 锁定读取所有已支付的记录，判断已支付金额
        $pays = PayModel::{'type' . Str::studly($order_type)}()->paid()->where('order_id', $order->id)->lock(true)->select();

        // 商城或者积分商城订单
        $payed_fee = '0';
        foreach ($pays as $key => $pay) {
            if ($pay->pay_type == 'score') {
                if ($order_type == 'order' && $order['type'] == 'goods') {
                    // 商城类型订单，并且不是积分商城订单，加上积分抵扣真实金额
                    $payed_fee = bcadd($payed_fee, $pay->real_fee, 2);
                } else {
                    // 其他类型，需要计算积分抵扣的金额时
                }
            } else {
                $payed_fee = bcadd($payed_fee, $pay->real_fee, 2);
            }
        }

        return $payed_fee;
    }



    /**
     * 获取剩余可退款的pays 记录（不含积分抵扣）
     * 
     * @param integer $order_id
     * @param string $sort  排序：money=优先退回代金券支付的钱
     * @return \think\Collection
     */
    public function getCanRefundPays($order_id, $sort = 'money')
    {
        // 商城订单，已支付的 pay 记录, 这里只查 钱的支付记录，不查积分
        $pays = PayModel::typeOrder()->paid()->isMoney()->where('order_id', $order_id)->lock(true)->order('id', 'asc')->select();
        $pays = collection($pays);
        if ($sort == 'money') {
            // 对 pays 进行排序，优先退 money 的钱
            $pays = $pays->sort(function ($a, $b) {
                if ($a['pay_type'] == 'money' && $b['pay_type'] == 'money') {
                    return 0;
                } else if ($a['pay_type'] == 'money' && $b['pay_type'] != 'money') {
                    return -1;
                } else if ($a['pay_type'] != 'money' && $b['pay_type'] == 'money') {
                    return 1;
                } else {
                    return 0;
                }
            });

            $pays = $pays->values();
        }

        return $pays;
    }



    /**
     * 获取剩余可退款金额，不含积分相关支付
     *
     * @param mixed $pays
     * @return string
     */
    public function getRemainRefundMoney($pays)
    {
        // 拿到 所有可退款的支付记录
        $pays = ($pays instanceof \think\Collection) ? $pays : $this->getCanRefundPays($pays);

        // 支付金额，除了已经退完款的金额 （这里不退积分）
        $payed_money = (string)array_sum($pays->column('pay_fee'));
        // 已经退款金额 （这里不退积分）
        $refunded_money = (string)array_sum($pays->column('refund_fee'));
        // 当前剩余的最大可退款金额，支付金额 - 已退款金额
        $remain_max_refund_money = bcsub($payed_money, $refunded_money, 2);

        return $remain_max_refund_money;
    }



    /**
     * 添加 pay 记录
     *
     * @param think\Model $order
     * @param array $params
     * @return think\Model
     */
    public function addPay($order, $params)
    {
        $payModel = new PayModel();

        $payModel->order_type = $params['order_type'];
        $payModel->order_id = $order->id;
        $payModel->pay_sn = get_sn($this->user->id, 'P');
        $payModel->user_id = $this->user->id;
        $payModel->pay_type = $params['pay_type'];
        $payModel->pay_fee = $params['pay_fee'];
        $payModel->real_fee = $params['real_fee'];
        $payModel->transaction_id = $params['transaction_id'];
        $payModel->payment_json = $params['payment_json'];
        $payModel->paid_time = $params['status'] == PayModel::PAY_STATUS_PAID ? time() : null;
        $payModel->status = $params['status'];
        $payModel->refund_fee = 0;
        $payModel->save();

        return $payModel;
    }


    public function getOrderModel($order_type)
    {
        switch ($order_type) {
            case 'trade_order':
                $orderModel = '\\app\\admin\\model\\shopro\\trade\\Order';
                break;
            case 'order':
                $orderModel = '\\app\\admin\\model\\shopro\\order\\Order';
                break;
            default:
                $orderModel = '\\app\\admin\\model\\shopro\\order\\Order';
                break;
        }

        return $orderModel;
    }
}
